home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / c / ExtrasLib.lha / ExtrasLib / Include / Extras / packdata.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  3.4 KB  |  101 lines

  1. #ifndef EXTRAS_PACKDATA_H
  2. #define EXTRAS_PACKDATA_H
  3.  
  4. #ifndef EXEC_TYPES_H
  5. #include <exec/types.h>
  6. #endif
  7.  
  8. #ifndef UTILITY_TAGITEM_H
  9. #include <utility/tagitem.h>
  10. #endif
  11.  
  12. #define PD_DUMMY     TAG_USER
  13.  
  14. /* Applicabiliy -- P PD_PackData,  U PD_UnpackData */
  15.  
  16. #define PD_Version   (1 + PD_DUMMY) /* (PU) Sets the version of the data */
  17. #define PD_IfVersion (2 + PD_DUMMY) /* (U)  If the data version is at least this value proceed, 
  18.                                             otherwise PD_UnpackData stops processing */
  19.  
  20. #define PD_BYTE      (3 + PD_DUMMY) /* (PU) */
  21. #define PD_UBYTE     (4 + PD_DUMMY) /* (PU) */
  22.  
  23. #define PD_WORD      (5 + PD_DUMMY) /* (PU) */
  24. #define PD_UWORD     (6 + PD_DUMMY) /* (PU) */
  25.  
  26. #define PD_LONG      (7 + PD_DUMMY) /* (PU) */
  27. #define PD_ULONG     (8 + PD_DUMMY) /* (PU) */
  28.  
  29. #define PD_STRPTR           (10 + PD_DUMMY) /* (P) NULL terminated string pointer
  30.                                                (U) Allocates memory with AllocVec
  31.                                                    FreeVec()s existing data if PD_FREESTRPTR is set */
  32. #define PD_UsedSTRPTR       (11 + PD_DUMMY) /* ?? (U) FreeVecs existing string before unpacking newstring */
  33. #define PD_STRPTRBufferSize (12 + PD_DUMMY) 
  34. #define PD_STRPTRBuffer     (13 + PD_DUMMY) /* ?? (U) unpacks string into existing buffer, buffersize must be set */
  35.  
  36. #define PD_APTRSize  (20 + PD_DUMMY) /* (PU) Length in bytes */ 
  37. #define PD_APTR      (21 + PD_DUMMY) /* (P) Data block to write
  38.                                         (U) Allocates memory with AllocVec() */ 
  39. #define PD_UsedAPTR  (22 + PD_DUMMY) /* (U) ??? When unpacking, the supplied memory pointed to by APTR will be 
  40.                                             FreeVec()ed before APTR is overwritten */
  41.  
  42. #define PD_BufferSize (30 + PD_DUMMY) /* (PU) Set size of data to pack or unpack */
  43. #define PD_Buffer     (31 + PD_DUMMY) /* (P) Pack BufferSize bytes of data.
  44.                                          (U) Data is read into existing memory */
  45.  
  46. #define PD_StructSize PD_BufferSize
  47. #define PD_Struct     PD_Buffer
  48.  
  49. #define PD_MemoryFlags  (100 + PD_DUMMY) /* (PU) Set memory flags for memory allocations */
  50. #define PD_FreeSTRPTR   (101 + PD_DUMMY) /* (U) When unpacking STRPTRs, if the supplied STRPTR address already points to string, FreeVec() it */
  51.  
  52. /* MACROS */
  53.  
  54. #define PD_STRUCT(o) PD_BufferSize, sizeof(o), PD_Buffer, &o /* (PU) pack:pack a struct or array - unpack:Reads data into an existing struct */
  55.  
  56. #define PD_PACK_TEXTATTR(t)\
  57. PD_STRPTR,  ((struct TextAttr *)t)->ta_Name,\
  58. PD_WORD,    ((struct TextAttr *)t)->ta_YSize,\
  59. PD_WORD,    ((struct TextAttr *)t)->ta_Style,\
  60. PD_WORD,    ((struct TextAttr *)t)->ta_Flags,
  61.  
  62. #define PD_UNPACK_TEXTATTR(t)\
  63. PD_STRPTR,  &((struct TextAttr *)t)->ta_Name,\
  64. PD_WORD,    &((struct TextAttr *)t)->ta_YSize,\
  65. PD_WORD,    &((struct TextAttr *)t)->ta_Style,\
  66. PD_WORD,    &((struct TextAttr *)t)->ta_Flags,
  67.  
  68.  
  69. //#define PD_ARRAYMACRO(ARRAY,ELEMENTS) PD_APTRSize, (sizeof((ARRAY)[0]) * (ELEMENTS), PD_APTR, (ARRAY),
  70.  
  71. /* ex.
  72.   struct cow herd[5];
  73.   
  74.  
  75.   if(PackedData=PackData(
  76.       PD_Version,     2,
  77.       PD_BYTE,        2,
  78.       PD_BYTE,        3,
  79.       PD_STRPTR,      "WRITE TEST",
  80.       
  81.       PD_ARRAYMACRO(myarray,10),
  82.       PD_ULONG,       longarray,
  83.       
  84.       PD_Array,       5,
  85.       PD_APTRSize,    sizeof(struct cow),
  86.       PD_APTR,        cows,
  87.       
  88.       TAG_DONE,       0))
  89.  
  90.       
  91. */
  92.  
  93. struct PackedData
  94. {
  95.   ULONG pd_DataSize;
  96.   UBYTE *pd_Data;
  97. };
  98.  
  99.  
  100. #endif /* EXTRAS_PACKDATA_H */
  101.